//1.添加material依赖
import 'package:flutter/material.dart';
import 'package:power_house/pages/home/tab_index/tab_index.dart';
import 'package:power_house/pages/home/tab_info/index.dart';
import 'package:power_house/pages/home/tab_profile/index.dart';
import 'package:power_house/pages/home/tab_search/index.dart';

// 1. 4个内容区域
List<Widget> tabViewList = [
  const TabIndex(),
  const TabSearch(),
  const TabInfo(),
  const TabProfile(),
];

//1. 4个BottomNavigationBarItem
List<BottomNavigationBarItem> bottomItemList = [
  const BottomNavigationBarItem(label: '首页', icon: Icon(Icons.home)),
  const BottomNavigationBarItem(label: '搜索', icon: Icon(Icons.search)),
  const BottomNavigationBarItem(label: '资讯', icon: Icon(Icons.info)),
  const BottomNavigationBarItem(label: '我的', icon: Icon(Icons.account_circle))
];

//2.编写无状态组件
class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  int _selectedIndex = 0;

  void _onItemClick(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: BottomNavigationBar(
        items: bottomItemList,
        currentIndex: _selectedIndex,
        type: BottomNavigationBarType.fixed,
        onTap: (index) {
          _onItemClick(index);
        },
      ),
      body:tabViewList[_selectedIndex],
    );
  }
}
